"""
【发送表单格式的post请求】，使用requests库，完成登录接口调用，返回“验证码错误”即可
请求地址是：
http://127.0.0.1/index.php?m=Home&c=User&a=do_login&t=0.999687125390627
请求头：Content-Type: application/x-www-form-urlencoded; charset=UTF-8
请求体：username=13800000000&password=123456&verify_code=8888

使用session管理cookie
"""
import requests
import re
class TestLogin:
    def test_login(self):
        ip = "http://123.57.228.35"
        url = f"{ip}/index.php?m=Home&c=User&a=do_login&t=0.014628845604706564"
        data = {
            "username": "15514091712",
            "password": "123456",
            "verify_code": "8888"
        }
        headers={
            "Content-Type": "application/x-www-form-urlencoded"
        }
        sess = requests.Session()
        sess.get(f"{ip}/index.php?m=Home&c=User&a=verify&r=0.17382934004161854")
        resp = sess.post(url, data=data, headers=headers)
        print(resp.cookies)
        print(resp.json())
        # p = re.search("'token':'(.+?)'", resp.text)
        # print(p)
        requests.put()